//
//  OSTopicVoiceView.m
//  百思不得姐
//
//  Created by PushMeBaby on 16/3/7.
//  Copyright © 2016年 CoderC. All rights reserved.
//

#import "OSTopicVoiceView.h"
#import "OSTopic.h"
#import "OSShowPictureViewController.h"

@interface OSTopicVoiceView ()

@property (weak, nonatomic) IBOutlet UIImageView *imageView;
@property (weak, nonatomic) IBOutlet UILabel *payCountLabel;

@property (weak, nonatomic) IBOutlet UILabel *playTimeLabel;

@end



@implementation OSTopicVoiceView
+(instancetype)voiceView{
    return [[[NSBundle mainBundle] loadNibNamed:@"OSTopicVoiceView" owner:nil options:nil] lastObject];
}
-(void)awakeFromNib{
    self.autoresizingMask = UIViewAutoresizingNone;
    
    self.imageView.userInteractionEnabled = YES;
    
    [self.imageView addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(showPicture)]];
    
}

-(void)setTopic:(OSTopic *)topic{
    _topic = topic;
    
    [self.imageView sd_setImageWithURL:[NSURL URLWithString:topic.middle_image]];
    
    self.payCountLabel.text = [NSString stringWithFormat:@"%zd播放",topic.playcount];
    NSInteger m = topic.voicetime / 60;
    NSInteger s = topic.voicetime % 60;
    self.playTimeLabel.text = [NSString stringWithFormat:@"%02zd:%02zd",m,s];
    
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/
- (void)showPicture
{
    OSShowPictureViewController *showPicture = [[OSShowPictureViewController alloc] init];
    showPicture.topic = self.topic;
    [[UIApplication sharedApplication].keyWindow.rootViewController presentViewController:showPicture animated:YES completion:nil];
}
@end
